1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
// app/api/tbe/sessions/[sessionId]/vendor-questions/route.ts
import { NextRequest, NextResponse } from "next/server"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
import {
addVendorQuestion,
getVendorQuestions,
answerVendorQuestion
} from "@/lib/tbe-last/vendor-tbe-service"
interface Props {
params: {
sessionId: string
}
}
// GET: 질문 목록 조회
export async function GET(
request: NextRequest,
{ params }: Props
) {
try {
const session = await getServerSession(authOptions)
if (!session?.user?.companyId) {
return NextResponse.json(
{ error: "Unauthorized" },
{ status: 401 }
)
}
const vendorId = typeof session.user.companyId === 'string'
? parseInt(session.user.companyId)
: session.user.companyId
const sessionId = parseInt(params.sessionId)
const questions = await getVendorQuestions(sessionId, vendorId)
return NextResponse.json(questions)
} catch (error) {
console.error("Get questions error:", error)
return NextResponse.json(
{ error: "Failed to get questions" },
{ status: 500 }
)
}
}
// POST: 새 질문 추가
export async function POST(
request: NextRequest,
{ params }: Props
) {
try {
const session = await getServerSession(authOptions)
if (!session?.user?.companyId) {
return NextResponse.json(
{ error: "Unauthorized" },
{ status: 401 }
)
}
const vendorId = typeof session.user.companyId === 'string'
? parseInt(session.user.companyId)
: session.user.companyId
const sessionId = parseInt(params.sessionId)
const body = await request.json()
const question = await addVendorQuestion(
sessionId,
vendorId,
{
category: body.category || "general",
question: body.question,
priority: body.priority || "normal",
status: "open"
}
)
return NextResponse.json(question)
} catch (error) {
console.error("Add question error:", error)
return NextResponse.json(
{ error: "Failed to add question" },
{ status: 500 }
)
}
}
// PATCH: 질문에 답변 추가 (구매자용)
export async function PATCH(
request: NextRequest,
{ params }: Props
) {
try {
const session = await getServerSession(authOptions)
if (!session?.user) {
return NextResponse.json(
{ error: "Unauthorized" },
{ status: 401 }
)
}
const sessionId = parseInt(params.sessionId)
const body = await request.json()
const { questionId, answer } = body
if (!questionId || !answer) {
return NextResponse.json(
{ error: "Question ID and answer are required" },
{ status: 400 }
)
}
const result = await answerVendorQuestion(sessionId, questionId, answer)
return NextResponse.json(result)
} catch (error) {
console.error("Answer question error:", error)
return NextResponse.json(
{ error: "Failed to answer question" },
{ status: 500 }
)
}
}
|